<template>
  <div class="overview-middle">
    <div class="box">
      <div class="box-item">
        <div class="box-item-num">
          {{ formatNum(data.stationData?.stationCount, 0).value
          }}<span
            v-if="formatNum(data.stationData?.stationCount, 0).state"
            class="box-item-unit"
            >万</span
          >
        </div>
        <div class="box-item-des">电站数</div>
      </div>
      <div class="box-item2">
        <div class="box-item2-num">
          {{ formatNum(data.stationData?.connectorCount, 0).value
          }}<span
            v-if="formatNum(data.stationData?.connectorCount, 0).state"
            class="box-item2-unit"
            >万</span
          >
        </div>
        <div class="box-item2-des">终端数</div>
      </div>
      <div class="box-item">
        <div class="box-item-num">
          {{ formatNum(data.orderData.orderCount, 0).value
          }}<span
            v-if="formatNum(data.orderData.orderCount, 0).state"
            class="box-item-unit"
            >万</span
          >
        </div>
        <div class="box-item-des">订单总数</div>
      </div>
      <div class="box-item2">
        <div class="box-item2-num">
          {{ formatNum(data.orderData.orderNum, 0).value
          }}<span
            v-if="formatNum(data.orderData.orderNum, 0).state"
            class="box-item2-unit"
            >万</span
          >
        </div>
        <div class="box-item2-des">当日订单数</div>
      </div>
    </div>
    <div class="mapbox">
      <chart-map
        :mapData="data.mapData"
        @change-station="changeStation"
      ></chart-map>
    </div>
    <div class="past-ten-days">
      <div class="title">
        <div class="title-des">近十天充电度数</div>
      </div>
      <div class="ul">
        <chart-past-ten :data="data.pastTenData"></chart-past-ten>
      </div>
    </div>
  </div>
</template>
<script lang="ts" setup>
import ChartMap from './chartMap.vue';
import ChartPastTen from './chartPastTen.vue';

interface Props {
  data: any;
}
withDefaults(defineProps<Props>(), {
  data: () => {},
});

const emit = defineEmits(['change-station']);

const changeStation = (val: string) => {
  console.log('object', val);
  emit('change-station', val);
};

const formatNum = (val: string | number, length: number = 3) => {
  if (isNaN(Number(val))) {
    return {
      value: '--',
      state: false,
    };
  }
  if (Number(val) > 10000) {
    return {
      value: `${parseFloat((Number(val) / 10000).toFixed(3))}`,
      state: true,
    };
  }

  return {
    value: Number(val).toFixed(length) || '0',
    state: false,
  };
};
</script>
<style lang="scss" scoped>
.overview-middle {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 0 19px;
  .title {
    width: 467px;
    height: 30px;
    background-image: url('@/assets/images/overView/title-bg.png');
    background-size: 100% 100%;
    background-repeat: no-repeat;
    margin-bottom: 3px;
    &-des {
      padding-top: 11px;
      padding-left: 32px;
      font-size: 12px;
      color: #dfeef3;
    }
  }
  .box {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-top: 18px;
    &-item {
      width: 122px;
      height: 128px;
      background-image: url('@/assets/images/overView/box.png');
      background-size: 100% 100%;
      background-repeat: no-repeat;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      margin: 0 9px;
      &-num {
        font-size: 23px;
        font-weight: bold;
        color: #65d9ff;
      }
      &-des {
        font-size: 16px;
        color: #ffffff;
      }
      &-unit {
        font-size: 10px;
        font-weight: normal;
      }
    }
    &-item2 {
      width: 122px;
      height: 128px;
      background-image: url('@/assets/images/overView/box.png');
      // background-image: url('@/assets/images/overView/box1.png');
      background-size: 100% 100%;
      background-repeat: no-repeat;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      margin: 0 4px;
      &-num {
        font-size: 23px;
        font-weight: bold;
        color: #ffd34b;
      }
      &-des {
        font-size: 16px;
        color: #ffffff;
      }
      &-unit {
        font-size: 10px;
        font-weight: normal;
      }
    }
  }

  .mapbox {
    height: 436px;
    display: flex;
    align-items: center;
    justify-content: center;
    // overflow: hidden;
  }
  .past-ten-days {
    position: relative;
    z-index: 2;
    .ul {
      box-sizing: border-box;
      width: 614px;
      height: 256px;
      border-radius: 5px;
      border: 1px solid rgba(48, 172, 243, 0.9);
    }
  }
}
</style>